package com.inossem.warehousestorage_inossem.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.inossem.warehousestorage_inossem.R;

public class LoadingDialog extends Dialog {
    private static LoadingDialog loadingDialog = null;

    private static Context mContext;

    private static String mMessage;

    private LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public static LoadingDialog createDialog(Context context, String message) {
        mMessage = message;
        mContext = context;
        // 设置样式
        loadingDialog = new LoadingDialog(mContext, R.style.LoadingDialog);
        return loadingDialog;
    }

    public static LoadingDialog createDialog(Context context) {
        return createDialog(context, "");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置布局
        loadingDialog.setContentView(R.layout.dialog_loading);
        // 设置位置
        loadingDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        setMessage(mMessage);
    }

    // 设置提示内容
    public LoadingDialog setMessage(String message) {
        TextView messageTextView = (TextView) loadingDialog.findViewById(R.id.message);
        messageTextView.setText(message);
        if (TextUtils.isEmpty(message)) {
            messageTextView.setVisibility(View.GONE);
        } else {
            messageTextView.setVisibility(View.VISIBLE);
        }
        return loadingDialog;
    }
}
